import React, { lazy } from "react";
import { Navigate } from "react-router-dom";
import Home from "@/components/layout/layout";
const Index = lazy(() => import("@/views/home/index"));
const Public = lazy(() => import("@/views/public/index"));
const Personal = lazy(() => import("@/views/personal/index"));
const Find = lazy(() => import("@/components/findPassword"));
const PlayPage = lazy(() => import("@/views/playPage"));
const Search = lazy(() => import("@/components/search"));
import AuthRoute from "@/components/authRouter";
import School from "@/views/school/index";
import AiVideo from "@/views/AiVideo";
// 路由懒加载
const lazyLoad = (el: JSX.Element) => {
  return <React.Suspense fallback={<>加载中...</>}>{el}</React.Suspense>;
};

// 路由表
const routes = [
  // 重定向
  {
    path: "/",
    element: <Navigate to="/home/index" />,
  },
  // layout
  {
    path: "/home",
    element: <Home />,
    children: [
      {
        path: "index",
        element: lazyLoad(<Index />),
      },
      {
        path: "public",
        element: lazyLoad(<Public />),
      },
      {
        path: "school",
        element: lazyLoad(<School />),
      },
      {
        path: "ai",
        element: lazyLoad(<AiVideo />),
      },
      {
        path: "personal",
        element: lazyLoad(
          <AuthRoute>
            <Personal />
          </AuthRoute>
        ),
      },
      {
        path: "playPage",
        element: lazyLoad(<PlayPage />),
      },
      {
        path: "search",
        element: lazyLoad(<Search />),
      },
    ],
  },
  {
    path: "/find",
    element: lazyLoad(<Find></Find>),
  },
];
export default routes;
